library dez1;

uses
  System.SysUtils,
  System.Classes,
  ActiveX,
  AxCtrls,
  IBC,
  pFIBDatabase,
  Vcl.Forms,
  dxCore,
  ibase,
  PluginAPI in '..\PluginAPI\Headers\PluginAPI.pas',
  Unit2 in 'Unit2.pas' {Form2},
  ConstList in 'ConstList.pas',
  dm in 'dm.pas' {dmd: TDataModule};

{$R *.res}
{$E .plg}

const
  SPluginID: TGUID = '{21AC3277-E842-487B-9D21-1FF45A341213}';
  SPluginName      = 'Example plugin';
  SPluginVersion   = '1.0.0.0';

type
  TPlugin = class(TInterfacedObject, IUnknown, IPlugin, IImportDB)
  private
    FCore: ICore;
    //fMainDB : TpFIBDatabase;
  protected
    // IPlugin
    //function GetMask: WideString; safecall;
    //function GetDescription: WideString; safecall;

    function GetID: TGUID; safecall;
    function GetName: WideString; safecall;
    function GetVersion: WideString; safecall;
    //IImportDB
    procedure SetDB(const fdb :TpFIBDatabase); safecall;
    procedure SetApp(const App,DLLApp :Integer); safecall;
    procedure ListDB(DBHandle: TISC_DB_HANDLE); safecall;
  public
    constructor Create(const ACore: ICore);
    //property MainDB :TpFIBDatabase read fMainDB write SetDB;
  end;
var
  Dll_App : TApplication;

{ TPlugin }

constructor TPlugin.Create(const ACore: ICore);
begin
  inherited Create;
  FCore := ACore;
  Assert(FCore.Version >= 1);
end;

{function TPlugin.GetDescription: WideString;
begin
  //
end;

function TPlugin.GetMask: WideString;
begin
  //
end;}

function TPlugin.GetID: TGUID;
begin
  Result := SPluginID;
end;

function TPlugin.GetName: WideString;
begin
  Result := SPluginName;
end;

function TPlugin.GetVersion: WideString;
begin
  Result := SPluginVersion;
end;

procedure TPlugin.ListDB(DBHandle: TISC_DB_HANDLE);
begin
  //MainDB:=dmd.fdb;
  //dmd.fdb.DesignDBOptions:=[];
  dmd.fdb.Handle:=DBHandle;
end;

procedure TPlugin.SetApp(const App,DLLApp: Integer);
begin
  Dll_App:=Application;
  Application:=TApplication(App);
end;

procedure TPlugin.SetDB(const fdb: TpFIBDatabase);
begin
  MainDB:=fdb;
end;

function Init(const ACore: ICore): IPlugin; safecall;
begin
  Result := TPlugin.Create(ACore);
  dxInitialize;
end;

procedure Done; safecall;
var
  i :Integer;
begin
  dxFinalize;
  MainDB:=nil;
  //i:=Integer(Dll_App);
  Application := Dll_App;
end;

exports
  Init name SPluginInitFuncName,
  Done name SPluginDoneFuncName;

//begin
  //ReportMemoryLeaksOnShutdown := True;

end.
